package org.jeecg.modules.demo.jxcx.Utils;

import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

/**
 * 描述：用来封装接口返回数据
 */
@Data
public class R<T> {
    /**
     * 状态码，0 success,1 fail
     */
    @ApiModelProperty("状态码，0 success,1 fail")
    private int code = 0;

    /**
     * 返回信息
     */
    @ApiModelProperty("返回信息")
    private String msg="success";

    /**
     * 返回的数据
     */
    @ApiModelProperty("返回数据")
    private T data;

    public R() {

    }

    public R(int code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public R<T> ok(T data){
        this.setData(data);
        return this;
    }

    public R<T> error(){
        this.code = 1;
        this.msg = "未知异常，请联系管理员";
        this.data = null;
        return this;
    }

    public R<T> error(String msg){
        this.code = 1;
        this.msg = msg;
        this.data = null;
        return this;
    }
}
